package projectjet;

import java.util.*;

public class HoldingSessions {
	private static  List<Session> socketsOfClients = new LinkedList<Session>();
	
        private static HashMap <String,Session > sessions = new HashMap<String,Session >();
	private static HashMap <String, String> channels = new HashMap <String, String >();
    
        public synchronized  HashMap<String,Session > getSessions(){
		return sessions;
	}

       public synchronized  HashMap<String,String > getChannels(){
		return channels;
	}
        
       public ArrayList<String> getClientsOnlineByChannel(String channelName){
          // System.out.println("getClientsOnlineByChannel ENTERED");
           ArrayList<String> username = new ArrayList<String>();
           
           for (String key : channels.keySet()) {
               //System.out.println("getClientsOnlineByChannel FOR ENTERED");
                if (channels.get(key).equals(channelName)) {
                    username.add(key);
                }
            }
           return username;
	}
 
        public Session getClientSession(String channelName, String userName){
            for (String user: getClientsOnlineByChannel(channelName)) {
                if(user.equals(userName)) return sessions.get(userName);
                
            }
            return null;
	}

}
